#!/bin/bash

#!/bin/bash
#一键修改网卡配置

#网卡文件备份
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33-$RANDOM

#替换为静态static
sed -i s/dhcp/static/ /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i s/ONBOOT=no/ONBOOT=yes/ /etc/sysconfig/network-scripts/ifcfg-ens33


grep "^IPADDR" /etc/sysconfig/network-scripts/ifcfg-ens33
if [ $? -eq 1 ];then
        printf "network is OK!"
        printf "nwk IP is:"`hostname -I`
else
    printf "IPADDR=192.168.44.99\n" >> /etc/sysconfig/network-scripts/ifcfg-ens33
    printf "MASK=255.255.255.0\n" >> /etc/sysconfig/network-scripts/ifcfg-ens33
    printf "GATEWAY=192.168.44.2\n" >> /etc/sysconfig/network-scripts/ifcfg-ens33
    printf "DNS1=192.168.44.2\n" >> /etc/sysconfig/network-scripts/ifcfg-ens33
    printf "DNS2=114.114.114.114\n" >> /etc/sysconfig/network-scripts/ifcfg-ens33
    nmcli c reload
    printf "success for config！"
fi